<template>
  <div class="getcode">
    <div class="swiper_Area">
      <SwiperScroll ref="swiperScroll" :sliderNum="3" :datasource="data" :autoPlay="true" :autoPlayTime="1000" :speed="1000">
        <template slot-scope="{ item }">
          <div class="scroll_item">
            <img src="https://image.hezongyy.com/pcimage/119h5/app_lb.png" alt="" />
            <span class="item">{{ item.username }}</span>
          </div>
        </template>
      </SwiperScroll>
    </div>
    <div class='top_Area'><img src="https://image.hezongyy.com/pcimage/119h5/app_bjt.jpeg" alt=""></div>
    <div class='gz_Area'><img src="https://image.hezongyy.com/pcimage/119h5/app_gz.png" alt="">
      <div class="info_block">
        <div class="code_item" v-if="this.userInfo.invitationCode">
          <div class='code'>{{ this.userInfo.invitationCode }}</div>
          <div class='text2'>我的邀请码</div>
          <button class="tag-read" :data-clipboard-text="
            '我的邀请码：' +
              this.userInfo.invitationCode +
              '\n ' +
              '合纵药易购邀请赚红包，提交订单时填写我分享的邀请码'+
              this.userInfo.invitationCode +'一起赚现金红包上不封顶，独乐乐不如众乐乐[调皮]'
          " @click="copy">
            <div class='btn'><img src="https://image.hezongyy.com/pcimage/119h5/app_fz.png" alt=""></div>
          </button>
        </div>
        <div class="nocode_item" v-else>
          <div class="btn">
            <img @click='goPlaceOrder' src="https://image.hezongyy.com/pcimage/119h5/app_qxd.png" alt="" />
          </div>
          <div class="text1">亲~您未有邀请码哦！</div>
          <div class="text2">未购买过的用户需先下单后才能生成邀请码哦!</div>
        </div>
      </div>
    </div>
    <div class='lc_Area'><img src="https://image.hezongyy.com/pcimage/119h5/app_lc.png" alt=""></div>
    <!-- <div class='btn-Area'>
      <img @click='goHome' src="https://image.hezongyy.com/pcimage/119h5/app_fhsy.png" alt="">
    </div> -->
  </div>
</template>
<script>
import SwiperScroll from '../../components/SwiperScroll'
import data from './data.js' //中奖名单假数据来源
import { getRequest } from '../../api/indexGet'
import url from '../../axios/apiUrl'
import Clipboard from 'clipboard' //实现复制

export default {
  components: {
    SwiperScroll,
  },
  data() {
    return {
      userInfo: {},
      data: data,
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.swiperScroll.refresh()
    })
    this.getUserInfo()
  },
  methods: {
    //去下单页面
    goPlaceOrder() {
       window.location.href=this.pathURL+"nativeApp/goodsList?title=‘普药列表’";
    },
    async getUserInfo() {
      let res = await getRequest(url.getUserInfo)
      if (res.data.code == '000000') {
        this.userInfo = res.data.content
      }
    },
    //复制操作
    copy() {
      var clipboard = new Clipboard('.tag-read')
      clipboard.on('success', (e) => {
        this.$toast({
          type: 'success',
          message: '复制成功',
          duration: 1000,
          offset: 400,
          showClose: true,
        })
        // 释放内存
        clipboard.destroy()
      })
      clipboard.on('error', (e) => {
        // 不支持复制
        this.$toast({
          type: 'error',
          message: '该浏览器不支持自动复制',
          duration: 1000,
          offset: 400,
          showClose: true,
        })
        // 释放内存
        clipboard.destroy()
      })
    },
  },
}
</script>
<style lang="less" src="./index.less" scoped></style>
